package com.lhnstart.learn.bases.date_;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 日期处理
 *
 * @author lhn
 * @date 2023/08/10 15:27
 * @since 1.0.0
 **/
public class DateFormat_ {

    public static void main(String[] args) {
        Date date = new Date();
        DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        System.out.println("format = " + format);

        String dateString = "2023-08-10 15:30:00";
        try {
            Date parsedDate = simpleDateFormat.parse(dateString); // 将字符串解析为 Date 对象
            System.out.println("Parsed Date: " + parsedDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

}